import request from '@/utils/request'

/**
 * 获取角色列表
 * @param {*} page 页码
 * @param {*} pagesize 每页条数
 */
export const reqGetRoleLise = (page, pagesize = 10) => {
  return request.get('/sys/role', {
    params: {
      page,
      pagesize
    }
  })
}

/**
 * 根据ID删除角色

 */
export const reqDelRole = id => request.delete(`/sys/role/${id}`)

/**
 * 添加角色
 * @param {*} form
 */
export const reqAddRole = (form) => {
  return request({
    method: 'post',
    url: '/sys/role',
    data: form
  })
}

/**
 * 根据id获取角色详情
 */
export const reqGetRoleDetail = (id) => {
  return request({
    method: 'get',
    url: `/sys/role/${id}`
  })
}

/**
 * 更新角色详情(form中需要有id以及其他信息)
 */
export const reqUpdateRole = (form) => {
  return request({
    method: 'put',
    url: '/sys/role/' + form.id,
    data: form
  })
}
/**
 * 给员工分配角色
 * @param {*} id 角色id
 * @param {*} roleIds 角色id组成的数组
 */
export const reqAssignRoles = (id, roleIds) => {
  return request({
    method: 'put',
    url: '/sys/user/assignRoles',
    data: {
      id,
      roleIds
    }
  })
}
